from config import host
from api import log


class ApiRiskTender:
    """
    封装风险评估和投资接口
    """

    # 初始化
    def __init__(self, session):
        # 获取session对象
        self.session = session
        # 获取风险评估URL
        self.risk_url = host+"/risk/answer/submit"
        # 获取投资URL
        self.tender_url = host+"/trust/trust/tender"

    # 1-封装风险评估接口
    def api_risk(self):
        # 1.构建请求参数
        data = {"answers_1": "A", "answers_2": "A", "answers_3": "A", "answers_4": "A", "answers_5": "A",
                "answers_6": "A", "answers_7": "A", "answers_8": "A", "answers_9": "A", "answers_10": "A"}
        # 调用session的post方法执行http请求，返回响应对象
        log.info("正在调用获取短信验证码接口，请求方法：{},请求URL：{},请求参数：{}".format("post", self.risk_url, data))
        return self.session.post(self.risk_url, data=data)

    # 2-封装投资接口
    def api_tender(self, amount):
        # 1.构建请求参数
        data = {
            "id": 642,
            "depositCertificate": -1,
            "amount": amount,
        }
        # 调用session的post方法执行http请求，返回响应对象
        log.info("正在调用获取短信验证码接口，请求方法：{},请求URL：{},请求参数：{}".format("post", self.tender_url, data))
        return self.session.post(self.tender_url, data=data)
